package com.example.springboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/src/main/resources/templates"); // 设置视图文件的前缀路径
        resolver.setSuffix(".html"); // 设置视图文件的后缀
        return resolver;
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                //这里要用绝对路径，不然要重启项目才能访问新上传的图片
                .addResourceLocations("file:E:\\VSCodeProject\\vue\\springboot\\src\\main\\resources\\static\\image");
        registry.addResourceHandler("/doc/**")
                .addResourceLocations("file:E:\\VSCodeProject\\vue\\springboot\\src\\main\\resources\\static\\document/");
    }
}